package com.naiterui.ehp.bs.wechat.controller;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.naiterui.ehp.bp.support.exception.BaseExceptionCodes;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bs.wechat.service.IJsApiService;
import com.naiterui.ehp.bs.wechat.vo.JsSdkVO;

/**
 * @author zhoupeipei
 * @date 2019-07-02 15:17
 * @since 1.0.0
 */
@RequestMapping("ap/openapi")
@RestController
public class WeChatJsTicketController {
    private static final Logger LOGGER = LoggerFactory.getLogger(WeChatJsTicketController.class);
    @Autowired
    IJsApiService jsApiService;

    @RequestMapping("jsticket")
    public ResponseVO<JsSdkVO> getJsTicket(String url) throws Exception {
        if (StringUtils.isBlank(url)) {
            LOGGER.error("参数错误，{}", url);
            return PublicService.returnResponseVO(BaseExceptionCodes.PARAM_ERROR, null);
        }
        JsSdkVO sdkVO = jsApiService.getJsSdkTicket(url);
        return PublicService.returnResponseVO(BaseExceptionCodes.SUCCESS, sdkVO);
    }

}
